<script type="text/javascript">
var s_q_row = 0;
var search_round = "init=all&index=";
function s_q_l_onSuccess(data) {
    console.log(data);
    s_q_l_operatedone(data.code, data.message, data.data);
  }

function s_q_l_onError(data) {
    console.log(data);
    s_q_l_operatedone( - 101, "服务器返回了未知的数据，请上报管理员", data.responseText);
}

function s_q_l_operatedone(id, message, data) {
    if (id == -101) {
        showMessage("s_q_e_message", -101, message + "<br><br><pre>" + data + "</pre>");
        return;
    }
    if (id != 0 && id != 3) {
        showMessage("s_q_e_message", id, message);
        return;
    }
    if (id == 0) {
        showMessage("s_q_e_message", id, message);
    }
    if(data.op=="chengemode"){
    	
			$(".s_q_load_more").html("加载更多");
			$(".s_q_load_more").removeClass("disabled");
		
    	$("#questions").html("");
		$("#s_q_f_round").html(data.round);
		search_round = data.search_round;
		$("#s_loadMore").click();
		
    }
    if(data.op=="load_more"){
		if(data.bottom){
			$(".s_q_load_more").html("到底了");
			$(".s_q_load_more").addClass("disabled");
		}
		s_q_load_list(data.data);
		s_q_row +=data.amount;
    }
    
}
function s_q_load_list(data){
	var $container = $("<div class='ui feed' id='offset-"+s_q_row+"'>")
	$.each(data,function(k,v){
		$container.prepend(s_q_loadQuestion(v));
	});
	$("#questions").append($container);
}
function s_q_loadQuestion(data){
	var $tmp = $("#question_temple").clone();
	$tmp.attr("id","").attr("style","");
	$tmp.find(".date").html("创建日期："+data.createdate+"<br>最后更新日期："+data.lastEditDate);
	$tmp.find(".s_qid").attr("qid",data.questionid);
	$tmp.find(".text").html(data.description);
	$tmp.find(".summary").html("标签：" + data.label);	
	return $tmp;
}
$(document).ready(function() {
    reloadListener();
    data = JSON.parse($(".s_temple_setting.mylist").html());
    $("#s_q_f_subject").html(data.subject.displayname);
    $("#s_q_f_round").html("全部");
    bindAjaxForm($("#s_q_l_search"),s_q_l_onSuccess,s_q_l_onError,"di");
});
function s_q_loadMore(){
	ajaxRequest(search_round+s_q_row,"index.php?mod=question&childmod=personal&ajax=true&op=search_load_more",s_q_l_onSuccess,s_q_l_onError,"di");
}
function s_q_editQuestion(qid){
	window.location="index.php?mod=question&childmod=personal&op=editquestion&qid="+qid;
}
</script>
<div class="s_temple_setting mylist"><?php print_json_setting("mylist");?></div>
<div class=" ui message hidden" id="s_q_l_message"></div>
<div class="ui segment">
	<form class="ui form s_q_l_search" id="s_q_l_search" url="index.php?mod=question&childmod=personal&ajax=true&op=search_request">
		<div class="field">
			<label>
				科目：
				<span id="s_q_f_subject"></span>
			</label>
		</div>
		<div class="field">
			<label>
				目前范围：
				<span id="s_q_f_round"></span>
			</label>
		</div>
		<div class="inline fields">
			<label for="fruit">阅读权限</label>
			<div class="field">
				<div id="view_level_0" class="ui radio checkbox">
					<input type="radio" name="view_level" value="-1" checked="" tabindex="0" class="hidden">
					<label>全部</label>
				</div>
			</div>
			<div class="field">
				<div id="view_level_0" class="ui radio checkbox">
					<input type="radio" name="view_level" value="0" tabindex="0" class="hidden">
					<label>仅自己可见</label>
				</div>
			</div>
			<div id="view_level_1" class="field">
				<div class="ui radio checkbox">
					<input type="radio" name="view_level" value="1" tabindex="0" class="hidden"">
					<label>教师团队可见</label>
				</div>
			</div>
			<div id="view_level_2" class="field">
				<div class="ui radio checkbox">
					<input type="radio" name="view_level" value="2" tabindex="0" class="hidden">
					<label>公开</label>
				</div>
			</div>
		</div>
		<div class="inline fields">
			<label for="fruit">排序方式</label>
			<div class="field">
				<div class="ui radio checkbox">
					<input type="radio" name="orderby" value="lastEditDate" checked="" tabindex="0" class="hidden">
					<label>依据最后编辑时间排序</label>
				</div>
			</div>
			<div class="field">
				<div class="ui radio checkbox">
					<input type="radio" name="orderby" value="createdate" tabindex="0" class="hidden">
					<label>依据创建时间排序</label>
				</div>
			</div>
		</div>
		<div class="two fields">
			<div class="field">
				<label>标题搜索</label>
				<input placeholder="标题" name="displaysearch" type="text">
			</div>
			<div class="field">
				<label>类别搜索（只能填一个）</label>
				<input placeholder="类别" name="labelsearch" type="text">
			</div>
		</div>
		<button class="ui submit button" type="submit">提交</button>
	</form>
</div>
<div class="ui feed" id="questions"></div>
<button class="ui fluid button s_q_load_more" onClick="if($(this).hasClass('disabled'))return; s_q_loadMore()">加载更多</button>
<div class="event" style="display: none" id="question_temple">
	<div class="label">
		<i class="book icon"></i>
	</div>
	<div class="content">
		<div class="lm_item s_qid" onClick="s_q_editQuestion($(this).attr('qid'))">编辑</div>
		<div class="lm_item s_qid" onClick="s_q_viewDetialQuestion($(this).attr('qid'))">查看详情</div>
		<div class="lm_item s_qid" onClick="s_q_setSimilarQuestion($(this).attr('qid'))">触类旁通</div>
		<div class="date"></div>
		<div class="summary"></div>
		<div class="extra text"></div>
	</div>
</div>
